﻿package{		
  import flash.display.GradientType;
  import flash.text.StyleSheet;
  import flash.filters.*;	
  import flash.display.Sprite;
  import flash.display.Shape;
  import flash.display.SimpleButton;
  import flash.events.MouseEvent;
  import flash.events.Event;
  import flash.text.TextField;
  import flash.text.TextFormat;
  import gs.TweenLite;
  import gs.easing.*;
  import flash.text.TextFormatAlign;
  import flash.geom.Transform;
  import flash.geom.Matrix;
  import flash.geom.Point;
  import flash.utils.Timer;
  import flash.events.TimerEvent;
	
  public class ButtonTrace extends Sprite {		
  private var container:Sprite=new Sprite();
  private var txt:TextField=new TextField();
  private var txtFormat:TextFormat=new TextFormat();
  private var spr:Sprite = new Sprite();
  private var holdTimer:Timer;
  private var __button:SimpleButton = new SimpleButton();
  private var holdDuration_ms:int =3;
	
  private var Waypoints:Array = new Array ();
  private var moveSpeed:Number= 3;
  private var  effect2:GlowFilter= new GlowFilter();
	
  public function set _txt(str:String):void
		{
			txt.text = str;
		}
  public function ButtonTrace():void {	
			var bien1:int= Main.stagex;
			var bien2:int= Main.stagey;
	 
			container.alpha=0;
			container.visible=false;
	  
	  		container.x=bien1;
	  		container.y=bien2;
	
	 		addChild(container);


			var container1=new Sprite();
			var colours=[0xA6A6A6,0x515151];
			var alphas=[1,1];
			var ratios=[0,255];
			var radians:Number=90*(Math.PI/180);
			var matrix:Matrix=new Matrix();
			matrix.createGradientBox(300,80,radians);
			container1.graphics.beginGradientFill(GradientType.LINEAR,colours,alphas,ratios,matrix);
			container1.graphics.drawRoundRect(0,0,300,80,5,5);
			
			var effect: DropShadowFilter= new DropShadowFilter();
	
	
			effect2.alpha=0.2;
			container1.filters=[effect,effect2];
				
	 		container1.transform.matrix= new Matrix(1,0,0,1,-container1.width>>1,-container1.height>>1);
	
	  		container.addChild(container1);
	 
	  
			txtFormat.color=0x000000;
			txtFormat.size=11;
			txtFormat.font="Times New Roman";
			txtFormat.align = TextFormatAlign.CENTER;
			txtFormat.bold=true;
			txt.defaultTextFormat=txtFormat;			
			txt.mouseEnabled=false;
			txt.text="First, you must click 'SELECT SIZE' for your choice and then select 'FIRM'. Finally, select car's 'NAME' for customized";
			txt.width=240;
			txt.height=container.height;
			//txt.border=true;
			//txt.borderColor=0xffffff;
			txt.wordWrap = true;
			
			var matrix:Matrix= new Matrix();
			var container2:Sprite= new Sprite();
			container2.addChild(txt);
			var effect1: GlowFilter= new GlowFilter();
			effect1.alpha=.15;
	        container2.filters=[effect1];
			container2.transform.matrix= new Matrix(1,0,0,1,-container2.width>>1,-(container.height>>1)+3);
			trace("toa do"+container.height/2);
			
			
			container.addChild(container2);
			
			
			//set text style
			
	  
	  
	  
	  		var down:Sprite = new Sprite();
     		down.graphics.lineStyle(1, 0x000000);
     		down.graphics.beginFill(0xFFCC00);
     		down.graphics.drawCircle(0,10,15);
			 
    		var up:Sprite = new Sprite();
     		up.graphics.lineStyle(1, 0xff0000);
    		up.graphics.beginFill(0x000000);
      		up.graphics.drawCircle(0,10,15);
			
     		var over:Sprite = new Sprite();
     		over.graphics.lineStyle(1, 0x000000);
     		over.graphics.beginFill(0x9966FF);
     		over.graphics.drawCircle(0,10,15);
			 
      		__button.upState = up;
    		__button.overState = over;
    		__button.downState = down;
     		__button.useHandCursor = true;
     		__button.hitTestState = up;
	 		 addEventListener(Event.ADDED_TO_STAGE,addedToStage);
     		var fg:Sprite = new Sprite();
			fg.graphics.lineStyle(1, 0x000000);
			fg.graphics.moveTo(-5, -5);
			fg.graphics.lineTo(5, 5);
			fg.graphics.moveTo(-5, 5);
			fg.graphics.lineTo(5, -5);
				
			fg.graphics.drawCircle(0,10,15);

		 	container.addChild(spr);

    }

	private function addedToStage(e:Event):void{ 
			stage.addEventListener(MouseEvent.MOUSE_DOWN,evtClick);
	}
	public function evtClick(evt:MouseEvent):void{

			if(container.alpha>0)
			TweenLite.to(container,.5,{autoAlpha:0,x:container.x,y:container.y,scaleX:0,scaleY:0}); 
		}

	public function open():void{
			
			container.scaleX=0;container.scaleY=0;
			if(container.alpha==0){
			container.visible=true;
			container.alpha=0;
			new TweenLite(container,1.5,{alpha:1,scaleX:1,scaleY:1,ease:Circ.easeInOut});
			}
			
		}


  }	
}